<template>
  <div class="lyricsbox">
    <div class="inner">
      <div class="lyleft">
        <div>
          <div class="imgbox">
            <img :src="getImgUrl" alt />
          </div>
          <div class="name">{{ getName }}</div>
          <div class="author">{{ getAuthor }}</div>
        </div>
      </div>
      <div class="lyright">
        <!-- <div class="close" @click="hidden">
          <span class="el-icon-close"></span>
        </div> -->
        <my-scroll ref="lyricsScroll" :opacity="0">
          <div class="lyricscontent">
            <ul v-if="getLyrics">
              <li
                v-for="(item, index) in getLyrics"
                :key="index"
                :class="getLyricsIndex == index ? 'currentLyric' : ''"
              >
                {{ item[1] }}
              </li>
            </ul>
            <span v-else>暂无歌词</span>
          </div>
        </my-scroll>
      </div>
      <div class="listbox">
        <div class="listitle">
          <span>播放列表：共 {{ getMusicList.length }} 首</span>
          <!-- <span>播放列表：共 10 首</span> -->
          <div>
            <span class="iconfont icon-zhuye" @click="goHome"></span>
            <span class="iconfont icon-close" @click="hidden"></span>
            <span class="el-icon-delete delete" @click="delall"></span>
          </div>
        </div>
        <div class="scrollbox">
          <my-scroll :opacity="0.5">
            <div
              v-for="(item, index) in getMusicList"
              :key="index"
              class="item"
            >
              <span
                class="name"
                :class="getIndex == index ? 'active_color' : ''"
                @click="playSong(index)"
                >{{ item.name }}</span
              >
              <span
                class="el-icon-delete delete"
                @click="deleteSong(index)"
              ></span>
            </div>
          </my-scroll>
        </div>
      </div>
    </div>
  </div>
</template>
<script>
import { mapGetters } from "vuex"
export default {
  name: "musiclyrics",
  data() {
    return {
      val: "",
      scrolltop: 0,
    }
  },
  computed: {
    // vue辅助函数
    ...mapGetters([
      "getName",
      "getAuthor",
      "getMusicUrl",
      "getImgUrl",
      "getIndex",
      "getModel",
      "getMusicList",
      "getState",
      "getDuration",
      "getCurrentTime",
      "getShowLyrics",
      "getLyrics",
      "getLyricsIndex",
    ]),
  },
  watch: {
    getLyricsIndex: function(newValue, oldValue) {
      if (newValue == 0) {
        this.scrolltop = 0
      }
      if (newValue >= 8) {
        this.scrolltop = (newValue - 6) * 30
      }
      this.$refs.lyricsScroll.$refs.vs.scrollTo({
        y: this.scrolltop,
      })
    },
  },
  methods: {
    hidden() {
      this.$EventBus.$emit("showMusicLyrics")
    },
    goHome() {
      this.$router.push("/")
    },
    formDate(date) {
      //格式化时间过滤器
      var m = parseInt(date / 60)
      if (m < 10) {
        m = "0" + m
      }
      var s = parseInt(date % 60)
      if (s < 10) {
        s = "0" + s
      }
      return m + ":" + s
    },
    // 点击播放列表
    playSong(index) {
      this.$store.commit("upDateIndex", index)
    },
    //删除播放列表里的歌曲
    deleteSong(index) {
      this.$store.commit("delete", index)
    },

    // 清空歌曲列表
    delall() {
      this.$confirm("此操作将永久删除该文件, 是否继续?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          this.$store.commit("deleteAll")
          this.$message({
            type: "success",
            message: "删除成功!",
          })
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消删除",
          })
        })
    },
  },
}
</script>
<style lang="scss" scoped>
@import "../../../scss/common.scss";
.lyricsbox {
  position: fixed;
  z-index: 9999;
  width: 100%;
  height: calc(100% - 50px);
  top: 0;
  left: 0;
  display: flex;
  justify-content: center;
  background: $bg_color2;
  .inner {
    width: 100%;
    max-width: 1200px;
    height: 100%;
    display: flex;
  }
  .lyleft {
    padding: 20px;
    box-sizing: border-box;
    display: flex;
    width: 200px;
    .imgbox {
      width: 200px;
      height: 200px;
      overflow: hidden;
      border-radius: 10px;
      img {
        width: 200px;
      }
    }
    .name {
      display: inline-block;
      width: 100%;
      color: white;
      font-size: 17px;
      text-align: left;
      padding: 10px;
      line-height: 25px;
      box-sizing: border-box;
      word-break: break-all;
      word-wrap: break-word;
    }
    .author {
      display: inline-block;
      width: 100%;
      color: white;
      font-size: 15px;
      padding: 0px 10px;
      box-sizing: border-box;
      text-align: left;
      word-break: break-all;
      word-wrap: break-word;
    }
  }
  .lyright {
    position: relative;
    padding: 20px;
    box-sizing: border-box;
    flex: auto;
    height: 100%;
    .lyricscontent {
      margin: 0 40px;
      height: 300px;
      ul {
        height: 300px;
        li {
          word-break: break-all;
          line-height: 30px;
          list-style: none;
          font-size: 14px;
          color: white;
        }
        .currentLyric {
          color: $primary;
        }
      }
    }
    span {
      font-size: 14px;
      color: rgb(161, 159, 159);
    }
  }
}
.listbox {
  height: 100%;
  width: 300px;
}
.listitle {
  height: 40px;
  font-size: 17px;
  display: flex;
  justify-content: space-between;
  border-bottom: 1px solid rgb(255, 255, 255);
  position: relative;
  z-index: 5;
  span {
    z-index: 1;
    color: rgb(255, 255, 255);
    display: inline-block;
    height: 40px;
    line-height: 40px;
    padding: 0px 10px;
  }
  div {
    span {
      color: rgb(255, 255, 255);
      padding: 0px 5px;
    }
    .icon-zhuye {
      font-size: 17.5px;
    }
    span:hover {
      color: #ad0a49;
      cursor: pointer;
    }
  }
}
.scrollbox {
  height: calc(100% - 40px);
}
.item {
  z-index: 1;
  line-height: 30px;
  height: 30px;
  color: rgb(255, 255, 255);
  font-size: 14px;
  width: 300px;
  vertical-align: middle;
  .name {
    vertical-align: middle;
    padding: 0px 10px;
    display: inline-block;
    width: 240px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
  .active_color {
    color: #ad0a49;
  }
  .delete {
    vertical-align: middle;
    width: 30px;
    display: inline-block;
    height: 30px;
    line-height: 30px;
    text-align: center;
    padding-right: 10px;
  }
  .delete:hover {
    color: crimson;
  }
}
.item:hover {
  cursor: pointer;
  background: $active;
  color: white;
}
.item:hover .name {
  color: white !important;
}
</style>
